﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CPPEI.Coolzon.Metadata;

namespace CPPEI.Coolzon.UI.XProperty.Converters
{
    public class XResourceFileConverter : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, ValueNode valueNode)
        {
            ResourceFile resourceFile = new ResourceFile(valueNode.Attributes["Value"]);
            return resourceFile;
        }

        public ValueNode ConvertBack(ConvertContext context, object value)
        {
            Metadata.ValueNode valueNode = new Metadata.ValueNode("String");
            valueNode.Attributes = new Dictionary<string, string>();
            valueNode.Attributes.Add("Value", value == null ? string.Empty : (value as ResourceFile).Path);
            return valueNode;
        }
    }
}
